package com.ums.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ums.core.entity.user.AddressDetail;
import com.ums.core.entity.user.User;
import com.ums.core.service.UserService;

public class UserAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private List<User> users = new ArrayList<User>();
	private String userName;
	private String password;
	private String userStr;
	
	public String initSearchUser() {
		return SUCCESS;
	}
	
	public String searchUser() throws Exception {

		super.execute();
		try {
			System.out.println("Inside User Action");
			
			UserService userService = new UserService();
			User searchUser = new User();
			searchUser.setUsername(userStr);
			users = userService.searchUser(searchUser);
			System.out.println("Inside User Action, users fetched");
		} catch (Exception e) {
			System.out.println("Some error occurred");
		}

		return SUCCESS;
	}
	
	public String createUser() throws Exception {

		super.execute();
		try {
			System.out.println("Inside Create User Action");
			
			UserService userService = new UserService();
			User user = new User();
			//user.setUserId(1);
			user.setUsername("manoj");
			user.setPassword("manoj");
			user.setUserTypeId("01UT01");
			user.setStatus("01US001");
			user.setIsAccountLocked("N");
			user.setIsActive("Y");
			user.setFirstName("fname");
			user.setLastName("lname");
			user.setCreatedBy(1);
			user.setCreateDate(new Date());
			user.setLastModifiedBy(1);
			user.setLastModifyDate(new Date());
			user.setIsSystemRecord("Y");
			
			AddressDetail addrDtl = new AddressDetail();
			//addrDtl.setAddressDtlId(1);
			//addrDtl.setUserId(1);
			addrDtl.setIsPrimary("Y");
			addrDtl.setAddress1("Maradia Plaza");
			addrDtl.setAddress2("C. G. Road");
			addrDtl.setCity("Ahmedabad");
			addrDtl.setState("Gujarat");
			addrDtl.setCountry("India");
			addrDtl.setMobile("9913603946");
			addrDtl.setPhone("079-4002427");
			addrDtl.setCreatedBy(1);
			addrDtl.setCreateDate(new Date());
			addrDtl.setLastModifiedBy(1);
			addrDtl.setLastModifyDate(new Date());
			addrDtl.setIsActive("Y");
			user.getAddrList().add(addrDtl);
			
			addrDtl = new AddressDetail();
			//addrDtl.setAddressDtlId(1);
			//addrDtl.setUserId(1);
			addrDtl.setIsPrimary("Y");
			addrDtl.setAddress1("National Plaza");
			addrDtl.setAddress2("C. G. Road");
			addrDtl.setCity("Ahmedabad");
			addrDtl.setState("Gujarat");
			addrDtl.setCountry("India");
			addrDtl.setMobile("9913603946");
			addrDtl.setPhone("079-4002427");
			addrDtl.setCreatedBy(1);
			addrDtl.setCreateDate(new Date());
			addrDtl.setLastModifiedBy(1);
			addrDtl.setLastModifyDate(new Date());
			addrDtl.setIsActive("Y");
			user.getAddrList().add(addrDtl);
			
			user = userService.createUser(user);
			System.out.println("Inside User Action, users fetched");
		} catch (Exception e) {
			System.out.println("Some error occurred");
			e.printStackTrace();
		}

		return SUCCESS;
	}

	/**
	 * @return the users
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @param users the users to set
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the userStr
	 */
	public String getUserStr() {
		return userStr;
	}

	/**
	 * @param userStr the userStr to set
	 */
	public void setUserStr(String userStr) {
		this.userStr = userStr;
	}

	/**
	 * @return the serialVersionUID
	 */
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	
	
}
